local shishen_rende = fk.CreateSkill {
  name = "th_shishen&",
}

shishen_rende:addEffect("active", {
  anim_type = "support",
  can_use = function(self, player)
    if player:isKongcheng() then return end
    return table.find(player:getTableMark("th_shishen"), function(ran)
      return ran and not ran.dead and Fk.skill_skels["th_shishen"]:withinBranchTimesLimit(ran, "others", Player.HistoryPhase)
    end)
  end,
  prompt = function(self, player, cards, targets)
    return targets[1] and "#th_shishen&:" .. targets[1].id or "#th_shishen&0"
  end,
  min_card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  target_num = function(self, player)
    if #table.filter(player:getTableMark("th_shishen"), function(ran)
      return ran and not ran.dead and Fk.skill_skels["th_shishen"]:withinBranchTimesLimit(ran, "others", Player.HistoryPhase)
    end) > 1 then
      return 1
    else
      return 0
    end
  end,
  target_filter = function(self, player, to_select, selected)
    if #table.filter(player:getTableMark("th_shishen"), function(ran)
      return ran and not ran.dead and Fk.skill_skels["th_shishen"]:withinBranchTimesLimit(ran, "others", Player.HistoryPhase)
    end) > 1 then
      return #selected == 0 and table.contains(player:getTableMark("th_shishen"), to_select) and Fk.skill_skels["th_shishen"]:withinBranchTimesLimit(to_select, "others", Player.HistoryPhase)
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = effect.tos[1] and effect.tos or table.filter(player:getTableMark("th_shishen"), function(ran)
      return ran and not ran.dead and Fk.skill_skels["th_shishen"]:withinBranchTimesLimit(ran, "others", Player.HistoryPhase)
    end)
    local ran
    if #targets == 1 then
      ran = targets[1]
    else
      ran = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = "th_shishen",
        prompt = "#th_shishen&0",
        cancelable = false,
      })[1]
    end
    ran:addSkillBranchUseHistory("th_shishen", "others")
    room:obtainCard(ran, effect.cards, false, fk.ReasonGive)
    player:drawCards(2, "th_shishen")
  end,
})

Fk:loadTranslationTable{
  ["th_shishen&"] = "式神",
  [":th_shishen&"] = "出牌阶段限一次，你可以交给蓝至少一张手牌，然后你摸两张牌。",

  ["#th_shishen&"] = "式神：交给%src至少一张手牌，然后你摸两张牌",
  ["#th_shishen&0"] = "式神：交给蓝至少一张手牌，然后你摸两张牌",
}

return shishen_rende